#ifndef BACKEND_LIST_H
#define BACKEND_LIST_H

#include <arpa/inet.h>
#include <netinet/in.h>
#include "configuration.h"
#include "http_connection.h"

typedef struct {
	buffer_t host;

	struct sockaddr_in addr;

	time_t last_connection;

	int weight;
} backend_t;

typedef struct {
	backend_t *backends;
	size_t size;
	size_t used;

	size_t current;
} backend_list_t;

void backend_list_init (backend_list_t *backend_list);
void backend_list_free (backend_list_t *backend_list);

int backend_list_load (backend_list_t *backend_list, configuration_t *conf, const char *host_name, const char *rule_name);

int backend_list_connect (backend_list_t *backend_list, http_connection_t *http_connection);
int backend_list_fcgi_connect (backend_list_t *backend_list, http_connection_t *http_connection);

#endif /* BACKEND_LIST_H */
